package handler;
import pojo.Student;
import java.io.*;
import java.util.*;

public class FileHandler {
    /** 用于读取文件内容*/
    public List<Student> fileHandler(String Path) throws IOException {
        String s;/** 用于接收读取结果*/
        BufferedReader reader;
        FileInputStream fr = new FileInputStream(Path);
        InputStreamReader re=new InputStreamReader(fr,"UTF-8");/** 指定读取的编码格式为UTF-8*/
        reader = new BufferedReader(re);
        List<Student> list1 = new ArrayList<Student>();
        while ((s = reader.readLine()) != null) {
            String[] fs = s.split(" ");/** 将学生的班级，成绩，姓名分割然后进行存储*/
            Student st = new Student();
            st.setClass1(fs[0]);
            st.setName(fs[1]);
            st.setGrade(fs[2]);
            System.out.println(fs[0]+" "+fs[1]+" "+fs[2]);/**这行是用来验证FileHandler读取数据是否正确*/
            list1.add(st);
        }
        return list1;/** 返回包含学生信息的列表*/
    }
}
